﻿using Autofac;
using Autofac.Core;
using Autofac.Extensions.DependencyInjection;
using Code.Repsitory.MenuRoles;
using Code.Repsitory.Roles;
using Code.Services.Email;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;

namespace CodeAPP.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]//局
    public class EmailController : ControllerBase
    {
        private readonly IEmailService emailService1;
        private readonly IServiceProvider service;

        public EmailController(IEmailService emailService1, IServiceProvider service)
        {
            this.emailService1 = emailService1;
            this.service = service;
        }

        public IMenuRoleRepository roleRepository { get; set; }

        [HttpGet]
        public IActionResult Test([FromServices] ILifetimeScope lifetime)
        {
            var s = roleRepository.QueryAll();
            var one = lifetime.ResolveNamed<IEmailService>("one");

            //其中service为在构造函数中注入的IServiceProvider接口
            var two = service.GetAutofacRoot().ResolveNamed<IEmailService>("two");

            return Ok();
        }
    }
}
